package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.IItemService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ItemService extends ServiceImpl<ItemMapper, Item> implements IItemService {

@Autowired
 ItemMapper itemMapper;
    /**
     * 新增商品
     * @param item
     */
    @Override
    public void addItem(Item item) {
        Item item1 = new Item();
        BeanUtils.copyProperties(item,item1);
        item1.setCreateTime(new Date());
        item1.setUpdateTime(new Date());
        itemMapper.insert(item1);
    }

    /**
     * 修改商品
     * @param id
     * @param status
     */
    @Override
    public void upOrDownItem(Long id, Integer status) {
        Item item = itemMapper.selectById(id);
        Integer status1 = item.getStatus();
        if (status1!=status) {
            item.setStatus(status);
            itemMapper.updateById(item);
        }
    }

    /**
     * 删除商品
     * @param id
     */
    @Override
    public void deleteItem(Long id) {
        int ids = itemMapper.deleteById(id);
        itemMapper.deleteById(ids);
    }

    @Override
    public void pageItem(Integer page, Integer size) {

    }

   /* @Override
    public void pageItem(Integer page, Integer size) {
        itemMapper.
    }*/


}
